<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Email_sender extends MY_Email {
	var $CI;
	var $fromEmail = "";
	var $toEmail = "";
	var $subject = "";
	var $body = "";
	var $emailAdmin = "finance@showbiz-exchange.com";
	
	function __construct( $config = array() ){
		parent::__construct($config);
		
		$this->CI = & get_instance();
		$this->CI->load->library('module_helper');
		
		$this->setFromEmail(Settings_class::get('server_email'));
	}	
	
	function setFromEmail($input){$this->fromEmail = $input;}
	function setToEmail($input){$this->toEmail = $input;}
	function setSubject($input){$this->subject = $input;}
	function setBody($input){$this->body = $input;}
	
	function sendEmail(){
		$this->from($this->fromEmail);
		$this->to($this->toEmail);
		$this->subject($this->subject);
		$this->message($this->body);
		
		if( ENVIRONMENT != 'local' ){
			$this->send();
		}else{
			$this->sendEmail2();
		}	
	}
	
	function sendEmail2(){
		require_once("PHPMailer/class.phpmailer.php");
		
		try {
			$mail = new PHPMailer(true); 
			$mail->IsSMTP(); // telling the class to use SMTP
			$mail->SMTPDebug  = 2; // enables SMTP debug information (for testing)               
			$mail->SMTPAuth   = true;                  // enable SMTP authentication
			$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
			$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
			$mail->Port       = 465;   
			$mail->Username   = "dangdinhhung241288@gmail.com";     // SMTP server username
			$mail->Password   = "123123911";            // SMTP server password

			$mail->From       = $this->fromEmail;
			$mail->FromName   = "Soteria auto email sender";

			$to = $this->toEmail;

			$mail->AddAddress($to);

			$mail->Subject  = $this->subject;
			$body = $this->body;
			$mail->MsgHTML($body);

			$mail->IsHTML(true); // send as HTML

			$mail->Send();
			echo 'Message has been sent.';
		} catch (phpmailerException $e) {
			echo $e->errorMessage();
		}
	}
	
	// 1. Send email to new user to confirm account.
	// slug: confirm-acc-setup
	// TPL_1
	function _sendEmailToUser_confirm($userId){
		$USER = clone_( $this->CI->user_entity->init('id',$userId) );
		$slug = "confirm-acc-setup";
		
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###COMPANY###}" ,"{###EMAIL###}", "{###PASSWD###}", "{###ACCOUNT_CODE###}" );
		
		$rplArr = array( $USER->getCompany() ,$USER->getEmail(), $USER->getPasswd() , $USER->getAccCode() );
		
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($USER->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		
		$this->sendEmail();
	}
	
	// 2. Send email to user forgot password to reset password
	// slug: send-forgot-password
	function _sendEmailToUser_forgotPassword($userId){
		$USER = clone_( $this->CI->user_entity->init('id',$userId) );
		$slug = "send-forgot-password";
		
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###PASSWD###}", "{###LINK###}" );
		
		$link = "<a href='".site_url('user/regenerate_password').'?email='.$USER->getEmail().'&code='.md5($USER->getActivatedCode())."'>".
				site_url('user/regenerate_password').'?email='.$USER->getEmail().'&code='.md5($USER->getActivatedCode())."</a>";
		$rplArr = array( $USER->getActivatedCode() , $link );
		
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($USER->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		
		$this->sendEmail();
	}
	
	//3. Send email to account modify notify 
	// slug: confirm-acc-change
	// TPL_2
	function _sendEmailToUser_editAccNotify($userId){
		$USER = clone_( $this->CI->user_entity->init('id',$userId) );
		$slug = "confirm-acc-change";
		
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###CONTENT###}" );
		if($USER->whoAmI() == 'seller'){
			$content  = "<table>";
			$content .= "<tr><td>Email</td> <td>".$USER->getEmail()."</td></tr>";
			$content .= "<tr><td>First name</td> <td>".$USER->getFirstName()."</td></tr>";
			$content .= "<tr><td>Last name</td> <td>".$USER->getLastName()."</td></tr>";
			$content .= "<tr><td>Job title</td> <td>".$USER->getJobTitle()."</td></tr>";
			$content .= "<tr><td>Company/Organization</td> <td>".$USER->getCompany()."</td></tr>";
			$content .= "<tr><td>Country</td> <td>".$USER->getCountry()."</td></tr>";
			$content .= "<tr><td>Address Line 1</td> <td>".$USER->getAddressLine1()."</td></tr>";
			$content .= "<tr><td>Address Line 2</td> <td>".$USER->getAddressLine2()."</td></tr>";
			$content .= "<tr><td>City</td> <td>".$USER->getCity()."</td></tr>";
			$content .= "<tr><td>State</td> <td>".$USER->getState()."</td></tr>";
			$content .= "<tr><td>Zip</td> <td>".$USER->getZip()."</td></tr>";
			$content .= "<tr><td>Workphone</td> <td>".$USER->getWorkPhone()."</td></tr>";
			$content .= "<tr><td>Mobile</td> <td>".$USER->getMobile()."</td></tr>";
			$content .= "</table>";
		}else{
			$content  = "<table>";
			$content .= "<tr><td>Email</td> <td>".$USER->getEmail()."</td></tr>";
			$content .= "<tr><td>First name</td> <td>".$USER->getFirstName()."</td></tr>";
			$content .= "<tr><td>Last name</td> <td>".$USER->getLastName()."</td></tr>";
			$content .= "<tr><td>Job title</td> <td>".$USER->getJobTitle()."</td></tr>";
			$content .= "<tr><td>Company/Organization</td> <td>".$USER->getCompany()."</td></tr>";
			$content .= "<tr><td>Company Website</td> <td>".$USER->getCompanyUrl()."</td></tr>";
			$content .= "<tr><td>Company Profile</td> <td>".$USER->getCompanyProfile()."</td></tr>";
			$content .= "<tr><td>Country</td> <td>".$USER->getCountry()."</td></tr>";
			$content .= "<tr><td>Address Line 1</td> <td>".$USER->getAddressLine1()."</td></tr>";
			$content .= "<tr><td>Address Line 2</td> <td>".$USER->getAddressLine2()."</td></tr>";
			$content .= "<tr><td>City</td> <td>".$USER->getCity()."</td></tr>";
			$content .= "<tr><td>State</td> <td>".$USER->getState()."</td></tr>";
			$content .= "<tr><td>Zip</td> <td>".$USER->getZip()."</td></tr>";
			$content .= "<tr><td>Workphone</td> <td>".$USER->getWorkPhone()."</td></tr>";
			$content .= "<tr><td>Mobile</td> <td>".$USER->getMobile()."</td></tr>";
			
			if(($USER->getShowType())){
				$array = showTypeDataConfig(); 
				$array2 = array();
				foreach(explode(',',$USER->getShowType()) as $element){
					$array2[] = $array[$element];
				}
				$showType= implode(', ',$array2);
			}else{
				$showType= "";
			}	
			$content .= "<tr><td>Show Type</td> <td>".$showType."</td></tr>";
			
			if(($USER->getCountryOrigin())){
				$array = countryOriginDataConfig(); 
				$array2 = array();
				foreach(explode(',',$USER->getCountryOrigin()) as $element){
					$array2[] = $array[$element];
				}
				$countryOrigin=  implode(', ',$array2);
			}else{
				$countryOrigin= "";
			}		
			$content .= "<tr><td>Country of Origin</td> <td>".$countryOrigin."</td></tr>";
			
			if(($USER->getMusicGenre())){
				$array = musicGenreDataConfig(); 
				$array2 = array();
				foreach(explode(',',$USER->getMusicGenre()) as $element){
					$array2[] = $array[$element];
				}
				$musicGenre = implode(', ',$array2);
			}else{
				$musicGenre = "";
			}	
			$content .= "<tr><td>Music Genre</td> <td>".$musicGenre."</td></tr>";
			$content .= "</table>";
		}
		
		$rplArr = array( $content );
		
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($USER->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		
		$this->sendEmail();
	}
	
	//4. Send confirm email to seller created show
	// slug: confirm-new-show-add
	// TPL_3
	function _sendEmailToUser_createNewShow($userId, $show_ref_no){
		$USER = clone_( $this->CI->user_entity->init('id',$userId) );
		$SHOW = clone_( $this->CI->show_entity->init('ref_no', $show_ref_no));
		$slug = "confirm-new-show-add";
		
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###REF_LINK###}", "{###SHOW###}", "{###BID_DUE_DATE###}" );
		
		$ref_link = "<a href='".site_url('seller/show_details/'.$SHOW->getRefNo())."'>".$SHOW->getRefNo()."</a>";
				
		$rplArr = array( $ref_link , $SHOW->getName(), sbxDateFormat($SHOW->getBidDueDate()) );
		
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($USER->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		
		$this->sendEmail();
	} 
	
	//5. Send email to all Buyers notify Show had been added
	// slug:notify-all-buyers-new-show-added
	// Then send email to seller notify email sent to buyer
	// slug2: notify-seller-show-has-been-notified-to-buyers
	// TPL_4
	// TPL_5
	function _sendEmailToBuyers_notifyNewShow($show_ref_no){
		$SHOW = clone_( $this->CI->show_entity->init('ref_no', $show_ref_no));
		$slug = "notify-all-buyers-new-show-added";
		
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array( "{###SHOW_LINK###}" );
		
		$show_link = "<a href='".site_url('buyer/shows/view/'.$SHOW->getRefNo())."'>".site_url('buyer/shows/view/'.$SHOW->getRefNo())."</a>";
				
		$rplArr = array( $show_link );
		
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$buyers = $this->CI->db->where('acc_type','buyer')->get(TBL_ACCOUNT)->result();
		foreach($buyers as $person){
			$this->setToEmail($person->email);
			$this->setSubject($subject);
			$this->setBody($body);		
			$this->sendEmail();
		}
		
		$SELLER = clone_($this->CI->user_entity->init('id', $SHOW->getUserCreatedId()));
		$slug = "notify-seller-show-has-been-notified-to-buyers";
		
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###REF_LINK###}", "{###SHOW###}", "{###BID_DUE_DATE###}" );
		
		$ref_link = "<a href='".site_url('seller/show_details/'.$SHOW->getRefNo())."'>".$SHOW->getRefNo()."</a>";
				
		$rplArr = array( $ref_link , $SHOW->getName(), sbxDateFormat($SHOW->getBidDueDate()) );
		
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($SELLER->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		
		$this->sendEmail();
	}
	
	//6. Send confirm email to seller edited show
	// slug: confirm-show-details-has-been-changed
	// Then send email to all buyers notify show has been edited
	// slug: notify-all-buyers-show-details-has-been-changed
	// TPL_6
	// TPL_7
	function _sendEmailToUser_editShow($userId, $show_ref_no){
		$USER = clone_( $this->CI->user_entity->init('id',$userId) );
		$SHOW = clone_( $this->CI->show_entity->init('ref_no', $show_ref_no));
		$slug = "confirm-show-details-has-been-changed";
		
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###REF_LINK###}", "{###SHOW###}", "{###BID_DUE_DATE###}", "{###CONTENT###}" );
		
		$ref_link = "<a href='".site_url('seller/show_details/'.$SHOW->getRefNo())."'>".$SHOW->getRefNo()."</a>";
		$content = 	"<a href='".site_url('seller/show_details/'.$SHOW->getRefNo())."'>".site_url('seller/show_details/'.$SHOW->getRefNo())."</a>";
		
		$rplArr = array( $ref_link , $SHOW->getName(), sbxDateFormat($SHOW->getBidDueDate()), $content );
		
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($USER->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		
		$this->sendEmail();
		
		
		$slug = "notify-all-buyers-show-details-has-been-changed";
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array( "{###LINK_SHOW###}" );
		
		$show_link = "<a href='".site_url('buyer/shows/view/'.$SHOW->getRefNo())."'>".site_url('buyer/shows/view/'.$SHOW->getRefNo())."</a>";
				
		$rplArr = array( $show_link );
		
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$buyers = $this->CI->db->where('acc_type','buyer')->get(TBL_ACCOUNT)->result();
		foreach($buyers as $person){
			$this->setToEmail($person->email);
			$this->setSubject($subject);
			$this->setBody($body);		
			$this->sendEmail();
		}
	}
	
	//7. Send email to Buyer confirm Bid submitted
	// slug: confirm-bid-has-been-submitted
	// Then send email to Seller notify
	// slug: notify-seller-bid-received-that-show
	// TPL_8
	// TPL_9
	function _sendEmailToUser_newBidSubmit($show_ref_no , $bid_id){
		$BID = clone_( $this->CI->bid_entity->init('id',$bid_id) ) ;
		if(! $BID){ return true;}
		$SHOW = clone_( $this->CI->show_entity->init('ref_no', $show_ref_no));
		$BUYER = clone_( $this->CI->user_entity->init('acc_code', $BID->getAccountCode())) ;
		$SELLER = clone_( $this->CI->user_entity->init('id', $SHOW->getUserCreatedId()));
		
		$slug = "confirm-bid-has-been-submitted";
		
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###REF_SHOW###}", "{###SHOW###}", "{###BID_DUE_DATE###}", "{###LINK_SHOW###}" );
		
		$ref_link = "<a href='".site_url('buyer/shows/view/'.$SHOW->getRefNo())."'>".$SHOW->getRefNo()."</a>";
		$link_show = 	"<a href='".site_url('buyer/shows/view/'.$SHOW->getRefNo())."'>".site_url('buyer/shows/view/'.$SHOW->getRefNo())."</a>";
		
		$rplArr = array( $ref_link , $SHOW->getName(), sbxDateFormat($SHOW->getBidDueDate()), $link_show );
		
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($BUYER->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();
		
		$slug = "notify-seller-bid-received-that-show";
		
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###LINK_BID###}");

		$link_bid = "<a href='".site_url('seller/show_manage/bid_details/?show_id='.$SHOW->getId().'&bid_id='.$BID->getId() )."'>".site_url('seller/show_manage/bid_details/?show_id='.$SHOW->getId().'&bid_id='.$BID->getId() )."</a>";
		
		$rplArr = array( $link_bid );
		
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($SELLER->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();
	}
	
	// 8. Buyer send question to Seller
	function _sendEmail_Buyer2Seller($emailContentId){
		$content = $this->CI->db->where('id',$emailContentId)->get(TBL_BUYER_MESSAGE)->result();
		$SHOW = clone_( $this->CI->show_entity->init('ref_no', $content[0]->show_ref_no));
		$SELLER = clone_( $this->CI->user_entity->init('id', $SHOW->getUserCreatedId()));
		
		$this->setToEmail($SELLER->getEmail());
		$this->setSubject($subject = $content[0]->subject);
		$this->setBody($body = $content[0]->message);
		$this->sendEmail();
	}
	
	//9. Send email when buyer cancel bid which they bided
	// slug: confirm-buyer-cancel-bid-submitted
	// Then send email to seller notify Bid had been deleted
	// slug: notify-seller-cancel-submitted-bid
	// deprecated
	function _sendEmailToUser_buyerCancelBid($show_ref_no, $user_id, $bid_id){
	/***
		$BUYER = clone_( $this->CI->user_entity->init('id', $user_id));
		$SHOW = clone_( $this->CI->show_entity->init('ref_no', $show_ref_no));
		$slug = "confirm-buyer-cancel-bid-submitted";
		
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###SHOW_REF###}", "{###SHOW###}", "{###BID_DUE_DATE###}" );
		
		$ref_link = "<a href='".site_url('buyer/shows/view/'.$SHOW->getRefNo())."'>".$SHOW->getRefNo()."</a>";
				
		$rplArr = array( $ref_link , $SHOW->getName(), sbxDateFormat($SHOW->getBidDueDate()) );
		
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($BUYER->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		
		$this->sendEmail();
		
		$slug = "notify-seller-cancel-submitted-bid";
		$SELLER = clone_( $this->CI->user_entity->init('id', $SHOW->getUserCreatedId()));
		
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###BID_REF###}", "{###SHOW###}", "{###BID_DUE_DATE###}" );
		
		$ref_link = "<a href='".site_url('seller/show_details/'.$SHOW->getRefNo())."'>".$bid_id."</a>";
				
		$rplArr = array( $ref_link , $SHOW->getName(), sbxDateFormat($SHOW->getBidDueDate()) );
		
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($SELLER->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		
		$this->sendEmail();
	***/
		return true;
	}
	
	//10. Send email to Seller confirm Bid awarded
	// slug:confirm-seller-bid-awarded
	// Then send email to Buyer who won notify
	// slug2:notify-buyer-successful-bid
	// Then send email to all Buyer who lost bid notify
	// slug3:notify-oter-buyers-who-bid-show-lost 
	// Then send email notify to bank 
	// slug4:notify-bank-show-seller-buyer-transaction-show //deprecated
	// TPL_12
	// TPL_13	
	// TPL_14
	function _sendEmailToUser_sellerAcceptBid($show_ref_no, $bid_id){
		$BID = clone_( $this->CI->bid_entity->init('id',$bid_id) ) ; if(! $BID){ return true;}		
		$SHOW = clone_( $this->CI->show_entity->init('ref_no', $show_ref_no));
		$BUYER_WON = clone_( $this->CI->user_entity->init('id', $SHOW->getUserBidWon())) ;
		$SELLER = clone_( $this->CI->user_entity->init('id', $SHOW->getUserCreatedId()));
		
		$slug = "confirm-seller-bid-awarded";
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###SHOW_REF###}", "{###BUYER_ACC_ID###}" );
		
		$ref_link = "<a href='".site_url('seller/show_details/'.$SHOW->getRefNo())."'>".$SHOW->getRefNo()."</a>";
		
		$rplArr = array( $ref_link , $BUYER_WON->getAccCode() );
		
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($SELLER->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();		
		
		$slug = "notify-buyer-successful-bid";
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###SHOW_REF###}", "{###SHOW###}", "{###BID_DUE_DATE###}" );
		
		$ref_link = "<a href='".site_url('buyer/shows/view/'.$SHOW->getRefNo())."'>".$SHOW->getRefNo()."</a>";
		$rplArr = array( $ref_link , $SHOW->getName(), sbxDateFormat($SHOW->getBidDueDate()) );
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($BUYER_WON->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();
		
			
		$slug = "notify-oter-buyers-who-bid-show-lost";
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###SHOW_REF###}", "{###SHOW###}", "{###BID_DUE_DATE###}" );
		
		$ref_link = "<a href='".site_url('buyer/shows/view/'.$SHOW->getRefNo())."'>".$SHOW->getRefNo()."</a>";
		$rplArr = array( $ref_link , $SHOW->getName(), sbxDateFormat($SHOW->getBidDueDate()) );
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$bib_lost = $this->CI->db->query("SELECT * FROM ".TBL_BID." WHERE show_ref_no='".$SHOW->getRefNo()."' AND account_code !='".$BUYER_WON->getAccCode()."'")->result();
		foreach($bib_lost as $lost){
			$BUYER_LOST = $this->CI->user_entity->init('acc_code', $lost->account_code);
			$this->setToEmail($BUYER_LOST->getEmail());
			$this->setSubject($subject);
			$this->setBody($body);
			$this->sendEmail();
		}
	/**	
		$slug = "notify-bank-show-seller-buyer-transaction-show";
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###SHOW_REF###}", "{###SHOW###}", "{###BID_AMOUNT###}" );
		
		$ref_link = "<a href='".site_url('buyer/shows/view/'.$SHOW->getRefNo())."'>".$SHOW->getRefNo()."</a>";
		$rplArr = array( $ref_link , $SHOW->getName(), $BID->getOfferPrice()." USD" );
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail(Settings_class::get('bank_email'));
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();
		**/
	}
	
	// 10. Send email remind Buyer send 50% of Escrow
	// slug: reminder-buyer-won-bid-escrow-pay-half
	// TPL_16
	function _sendEmailToUser_remindBuyerPayEscrow($show_ref_no, $bid_id){
		$BID = clone_( $this->CI->bid_entity->init('id',$bid_id) ) ; if(! $BID){ return true;}		
		$SHOW = clone_( $this->CI->show_entity->init('ref_no', $show_ref_no));
		$BUYER_WON = clone_( $this->CI->user_entity->init('id', $SHOW->getUserBidWon())) ;
		
		$slug = "reminder-buyer-won-bid-escrow-pay-half";
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###SHOW_REF###}", "{###SHOW###}", "{###BID_DUE_DATE###}" );
		
		$ref_link = "<a href='".site_url('buyer/shows/view/'.$SHOW->getRefNo())."'>".$SHOW->getRefNo()."</a>";
		$rplArr = array( $ref_link , $SHOW->getName(), sbxDateFormat($SHOW->getBidDueDate()) );
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($BUYER_WON->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();
	}
	
	// 11. Send email notify to seller that escrow release
	// slug: notify-seller-escrow-fund-released
	// Send email to buyer notify escrow release
	// slug: notify-buyer-escrow-fund-released
	// TPL_19
	function _sendEmailToSeller_escrowReleaseNotify($show_id, $bid_id){
		$BID = clone_( $this->CI->bid_entity->init('id',$bid_id) ) ; if(! $BID){ return true;}		
		$SHOW = clone_( $this->CI->show_entity->init('id', $show_id));
		$SELLER = clone_( $this->CI->user_entity->init('id', $SHOW->getUserCreatedId())) ;
		$BUYER = clone_( $this->CI->user_entity->init('id', $SHOW->getUserBidWon())) ;
		
		$slug = "notify-seller-escrow-fund-released";
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###SHOW_REF###}", "{###SHOW###}", "{###AMOUNT###}", "{###LINK_RECEIPT###}" );
		
		$ref_link = "<a href='".site_url('seller/show_details/'.$SHOW->getRefNo())."'>".$SHOW->getRefNo()."</a>";
		$link_receipt = "<a href='".site_url('user/confirm2/?show_ref='.$SHOW->getRefNo().'&scrid='.$SHOW->makescrid())."'>Click here</a>";
		$rplArr = array( $ref_link , $SHOW->getName(), $BID->getOfferPrice(), $link_receipt );
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($SELLER->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();
		
		$slug = "notify-buyer-escrow-fund-released";
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###SHOW_REF###}", "{###SHOW###}", "{###AMOUNT###}" );
		
		$ref_link = "<a href='".site_url('buyer/shows/view/'.$SHOW->getRefNo())."'>".$SHOW->getRefNo()."</a>";
		$rplArr = array( $ref_link , $SHOW->getName(), $BID->getOfferPrice() );
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($BUYER->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();
	}
	
	// 12. Send email to Buyer notify send second escrow
	// slug:notify-buyer-payment-second-escrow
	// deprecated
	function _sendEmailToBuyer_escrowPaymentNotify($show_ref_no, $bid_id, $pay_due_date){
		/**
		$BID = clone_( $this->CI->bid_entity->init('id',$bid_id) ) ; if(! $BID){ return true;}		
		$SHOW = clone_( $this->CI->show_entity->init('ref_no', $show_ref_no));
		$SELLER = clone_( $this->CI->user_entity->init('id', $SHOW->getUserCreatedId())) ;
		$BUYER = clone_( $this->CI->user_entity->init('id', $SHOW->getUserBidWon())) ;
		
		$slug = "notify-buyer-payment-second-escrow";
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###SHOW_REF###}", "{###SHOW###}", "{###PAY_DUE_DATE###}"  );
		
		$ref_link = "<a href='".site_url('buyer/shows/view/'.$SHOW->getRefNo())."'>".$SHOW->getRefNo()."</a>";
		$rplArr = array( $ref_link , $SHOW->getName(), sbxDateFormat($pay_due_date) );
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($BUYER->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();		
		**/
		return true;
	}
	
	// 13. Send email to Buyer remind send second escrow
	// slug:reminder-buyer-second-payment-due-date
	// deprecated
	function _sendEmailToBUYER_remindBuyerPaySecondEscrow($show_ref_no, $bid_id, $pay_due_date){
	/**
		$BID = clone_( $this->CI->bid_entity->init('id',$bid_id) ) ; if(! $BID){ return true;}		
		$SHOW = clone_( $this->CI->show_entity->init('ref_no', $show_ref_no));
		$SELLER = clone_( $this->CI->user_entity->init('id', $SHOW->getUserCreatedId())) ;
		$BUYER = clone_( $this->CI->user_entity->init('id', $SHOW->getUserBidWon())) ;
		
		$slug = "notify-buyer-payment-second-escrow";
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###SHOW_REF###}", "{###SHOW###}", "{###PAY_DUE_DATE###}"  );
		
		$ref_link = "<a href='".site_url('buyer/shows/view/'.$SHOW->getRefNo())."'>".$SHOW->getRefNo()."</a>";
		$rplArr = array( $ref_link , $SHOW->getName(), sbxDateFormat($pay_due_date) );
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($BUYER->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();	
		**/
		return true;
	}
	
	//14. Send email to Buyer notify bid had changed
	// slug: confirm-buyer-changes-for-submitted-bid
	// slug: notify-seller-changed-made-submitted-bid
	// TPL_10
	// TPL_11
	function _sendEmailToUser_bidEdit($show_ref_no, $bid_id){
		$BID = clone_( $this->CI->bid_entity->init('id',$bid_id) ) ;
		if(! $BID){ return true;}
		$SHOW = clone_( $this->CI->show_entity->init('ref_no', $show_ref_no));
		$BUYER = clone_( $this->CI->user_entity->init('acc_code', $BID->getAccountCode())) ;
		$SELLER = clone_( $this->CI->user_entity->init('id', $SHOW->getUserCreatedId()));
		
		$slug = "confirm-buyer-changes-for-submitted-bid";
		
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###REF_SHOW###}", "{###SHOW###}", "{###BID_DUE_DATE###}", "{###LINK_SHOW###}" );
		
		$ref_link = "<a href='".site_url('buyer/shows/view/'.$SHOW->getRefNo())."'>".$SHOW->getRefNo()."</a>";
		$link_show = 	"<a href='".site_url('buyer/shows/view/'.$SHOW->getRefNo())."'>".site_url('buyer/shows/view/'.$SHOW->getRefNo())."</a>";
		
		$rplArr = array( $ref_link , $SHOW->getName(), sbxDateFormat($SHOW->getBidDueDate()), $link_show );
		
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($BUYER->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();
		
		$slug = "notify-seller-changed-made-submitted-bid";
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###REF_SHOW###}", "{###SHOW###}", "{###BID_DUE_DATE###}", "{###LINK_SHOW###}" );
		
		$ref_link = "<a href='".site_url('seller/show_details/'.$SHOW->getRefNo())."'>".$SHOW->getRefNo()."</a>";
		$link_show = 	"<a href='".site_url('seller/show_details/'.$SHOW->getRefNo())."'>".site_url('seller/show_details/'.$SHOW->getRefNo())."</a>";
		
		$rplArr = array( $ref_link , $SHOW->getName(), sbxDateFormat($SHOW->getBidDueDate()), $link_show );
		
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($SELLER->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();	
	}
	
	// 15. Send email to Buyer notify send 50% of Escrow
	// slug: notify-buyer-payment-escrow-5-work-days
	// TPL_15
	function _sendEmailToUser_notifyBuyerPayEscrow($show_ref_no, $bid_id){
		$BID = clone_( $this->CI->bid_entity->init('id',$bid_id) ) ; if(! $BID){ return true;}		
		$SHOW = clone_( $this->CI->show_entity->init('ref_no', $show_ref_no));
		$BUYER_WON = clone_( $this->CI->user_entity->init('id', $SHOW->getUserBidWon())) ;
		
		$slug = "notify-buyer-payment-escrow-5-work-days";
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###SHOW_REF###}", "{###SHOW###}", "{###BID_DUE_DATE###}" );
		
		$ref_link = "<a href='".site_url('buyer/shows/view/'.$SHOW->getRefNo())."'>".$SHOW->getRefNo()."</a>";
		$rplArr = array( $ref_link , $SHOW->getName(), sbxDateFormat($SHOW->getBidDueDate()) );
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($BUYER_WON->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();
	}
	
	// 16. Send email to Seller notify Escrow receipt
	// slug: notify-seller-escrow-receipt
	// TPL_18
	function _sendEmailToUser_notifySellerEscrowReceipt($show_ref_no){
		$SHOW = clone_( $this->CI->show_entity->init('ref_no', $show_ref_no));
		$BUYER_WON = clone_( $this->CI->user_entity->init('id', $SHOW->getUserBidWon())) ;
		$SELLER = clone_($this->CI->user_entity->init('id', $SHOW->getUserCreatedId()));
		
		$slug = "notify-seller-escrow-receipt";
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###SHOW_REF###}", "{###SHOW###}", "{###ACCOUNT_NUMBER###}", "{###BUYER_DETAILS###}" );
		
		$account_bank = "Bank name account: ".$SELLER->getBankNameAcc()."<br/>";
		$account_bank .= "Bank account number: ".$SELLER->getBankAccNo()."<br/>";
		$account_bank .= "Bank name: ".$SELLER->getBankName()."<br/>";
		$account_bank .= "Bank address: ".$SELLER->getBankAddress()."<br/>" ;
		$account_bank .= "Swift code: ".$SELLER->getSwiftCode() ;
		
		$content  = "<table>";
		$content .= "<tr><td>Email</td> <td>".$BUYER_WON->getEmail()."</td></tr>";
		$content .= "<tr><td>First name</td> <td>".$BUYER_WON->getFirstName()."</td></tr>";
		$content .= "<tr><td>Last name</td> <td>".$BUYER_WON->getLastName()."</td></tr>";
		$content .= "<tr><td>Job title</td> <td>".$BUYER_WON->getJobTitle()."</td></tr>";
		$content .= "<tr><td>Company/Organization</td> <td>".$BUYER_WON->getCompany()."</td></tr>";
		$content .= "<tr><td>Company Website</td> <td>".$BUYER_WON->getCompanyUrl()."</td></tr>";
		$content .= "<tr><td>Company Profile</td> <td>".$BUYER_WON->getCompanyProfile()."</td></tr>";
		$content .= "<tr><td>Country</td> <td>".$BUYER_WON->getCountry()."</td></tr>";
		$content .= "<tr><td>Address Line 1</td> <td>".$BUYER_WON->getAddressLine1()."</td></tr>";
		$content .= "<tr><td>Address Line 2</td> <td>".$BUYER_WON->getAddressLine2()."</td></tr>";
		$content .= "<tr><td>City</td> <td>".$BUYER_WON->getCity()."</td></tr>";
		$content .= "<tr><td>State</td> <td>".$BUYER_WON->getState()."</td></tr>";
		$content .= "<tr><td>Zip</td> <td>".$BUYER_WON->getZip()."</td></tr>";
		$content .= "<tr><td>Workphone</td> <td>".$BUYER_WON->getWorkPhone()."</td></tr>";
		$content .= "<tr><td>Mobile</td> <td>".$BUYER_WON->getMobile()."</td></tr>";
		$content .= "</table>";
		
		$ref_link = "<a href='".site_url('seller/show_details/'.$SHOW->getRefNo())."'>".$SHOW->getRefNo()."</a>";
		$rplArr = array( $ref_link , $SHOW->getName(), $account_bank, $content );
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($SELLER->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();
	}
	
	// 17. Send email to Seller notify Bid are closed
	// slug: notify-seller-bid-closed-ready-award-selection
	// TPL_29
	function _sendEmailToUser_notifySellerBidClosed($show_ref_no){
		$SHOW = clone_( $this->CI->show_entity->init('ref_no', $show_ref_no));
		$SELLER = clone_($this->CI->user_entity->init('id', $SHOW->getUserCreatedId()));
		
		$slug = "notify-seller-bid-closed-ready-award-selection";
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###SHOW_REF###}", "{###SHOW###}", "{###BID_DUE_DATE###}" );
		
		$ref_link = "<a href='".site_url('seller/show_details/'.$SHOW->getRefNo())."'>".$SHOW->getRefNo()."</a>";
		$rplArr = array( $ref_link , $SHOW->getName(), sbxDateFormat($SHOW->getBidDueDate()) );
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($SELLER->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();
	}
	
	// 18. Send email to admin notify send email to BANK
	// slug: remind_admin_send_email_to_bank
	// TPL_17
	function _sendEmailToAdmin_notifySendEmailToBank($show_ref_no){
		$SHOW = clone_( $this->CI->show_entity->init('ref_no', $show_ref_no));
		$BUYER = clone_( $this->CI->user_entity->init('id',$SHOW->getUserBidWon()));
		$BID = clone_( $this->CI->bid_entity->is_set($account_code= $BUYER->getAccCode(), $show_ref_no=$SHOW->getRefNo()) );
		
		$slug = "remind_admin_send_email_to_bank";
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array("{###SHOW_REF###}", "{###SHOW###}", "{###BID_AMOUNT###}" );
		
		$ref_link = "<a href='".site_url('admin/dataman/show/bid/?show_id='.$SHOW->getId())."'>".$SHOW->getRefNo()."</a>";
		$rplArr = array( $ref_link , $SHOW->getName(), $BID->getOfferPrice()." USD" );
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($this->emailAdmin);
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();
	}
	
	
	// 19. Send email to admin notify send email to Seller
	// slug: notify_admin_send_email_to_seller_reassign_bid
	// TPL_14a
	function _sendEmailToAdmin_notifySendEmailToSeller1($show_ref_no){
		$SHOW = clone_( $this->CI->show_entity->init('ref_no', $show_ref_no));
		$BUYER = clone_( $this->CI->user_entity->init('id',$SHOW->getUserBidWon()));
		$SELLER = clone_( $this->CI->user_entity->init('id',$SHOW->getUserCreatedId()));
		$BID = clone_( $this->CI->bid_entity->is_set($account_code= $BUYER->getAccCode(), $show_ref_no=$SHOW->getRefNo()) );
		
		$slug = "notify_admin_send_email_to_seller_reassign_bid";
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		
		$ref_link = "<a href='".site_url('admin/dataman/show/bid/?show_id='.$SHOW->getId())."'>".$SHOW->getRefNo()."</a>";
		$orgArr = array(		"{###SHOW_REF###}" , "{###SHOW###}", "{###BID_AMOUNT###}", 
								"{###BUYER_ID###}", "{###BUYER_NAME###}", "{###BUYER_EMAIL###}", 
								"{###BUYER_MOBILE###}", "{###SELLER_ID###}", "{###SELLER_NAME###}",
								"{###SELLER_EMAIL###}", "{###SELLER_MOBILE###}"
						);
		
		$rplArr = array( 	
							$ref_link , $SHOW->getName(), $BID->getOfferPrice()." USD" ,
							$BUYER->getAccCode(), $BUYER->getFirstName().' '.$BUYER->getLastName(), $BUYER->getEmail(),$BUYER->getWorkPhone(),
							$SELLER->getAccCode(), $SELLER->getFirstName().' '.$SELLER->getLastName(), $SELLER->getEmail(),$SELLER->getWorkPhone()
						);
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($this->emailAdmin);
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();
	}
	
	// 20. Notification to admin to inform bank that1st buyer has withdraw. New Buyer will be assigned
	// slug: notify_admin_inform_bank_buyer_withdraw
	// TPL_14b
	function _sendEmailToAdmin_notifyAdminInformBank($show_ref_no){
		$SHOW = clone_( $this->CI->show_entity->init('ref_no', $show_ref_no));
		$BUYER = clone_( $this->CI->user_entity->init('id',$SHOW->getUserBidWon()));
		$BID = clone_( $this->CI->bid_entity->is_set($account_code= $BUYER->getAccCode(), $show_ref_no=$SHOW->getRefNo()) );
		
		$slug = "notify_admin_inform_bank_buyer_withdraw";
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array(		"{###SHOW_REF###}", "{###SHOW###}", "{###BID_AMOUNT###}", 
								"{###BUYER_ID###}", "{###BUYER_NAME###}", "{###BUYER_EMAIL###}", 
								"{###BUYER_MOBILE###}" 
						);
		$ref_link = "<a href='".site_url('admin/dataman/show/bid/?show_id='.$SHOW->getId())."'>".$SHOW->getRefNo()."</a>";
		$rplArr = array( 	
							$ref_link , $SHOW->getName(), $BID->getOfferPrice()." USD" ,
							$BUYER->getAccCode(), $BUYER->getFirstName().' '.$BUYER->getLastName(), 
							$BUYER->getEmail(),$BUYER->getWorkPhone()
						);
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($this->emailAdmin);
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();
	}
	
	
	//21. Notification to Admin to send emails to Buyer and seller for release of contact details
	// slug: notify_admin_release_contact_buyer_seller
	// TPL_18a
	function _sendEmailToAdmin_notifyReleaseContact($show_ref_no){
		$SHOW = clone_( $this->CI->show_entity->init('ref_no', $show_ref_no));
		$BUYER = clone_( $this->CI->user_entity->init('id',$SHOW->getUserBidWon()));
		$SELLER = clone_( $this->CI->user_entity->init('id',$SHOW->getUserCreatedId()));
		$BID = clone_( $this->CI->bid_entity->is_set($account_code= $BUYER->getAccCode(), $show_ref_no=$SHOW->getRefNo()) );
		
		$slug = "notify_admin_release_contact_buyer_seller";
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array(		"{###SHOW_REF###}", "{###SHOW###}", 
								"{###BUYER_NAME###}", "{###BUYER_EMAIL###}", "{###BUYER_MOBILE###}",
								"{###SELLER_NAME###}", "{###SELLER_EMAIL###}", "{###SELLER_MOBILE###}"
						);
		$ref_link = "<a href='".site_url('admin/dataman/show/bid/?show_id='.$SHOW->getId())."'>".$SHOW->getRefNo()."</a>";
		$rplArr = array( 	
							$ref_link , $SHOW->getName(),  
							$BUYER->getFirstName().' '.$BUYER->getLastName(), $BUYER->getEmail(),$BUYER->getWorkPhone(),
							$SELLER->getFirstName().' '.$SELLER->getLastName(), $SELLER->getEmail(),$SELLER->getWorkPhone()
						);
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($this->emailAdmin);
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();
	
	}
	
	//22. Reminder to Admin to send email to Bank to release funds, net of fees and commission to SBX
	// slug: notify_admin_send_email_to_bank_release_fund
	// TPL_20a
	function _sendEmailToAdmin_notifyAdminSendEmailToBankReleaseFund($show_ref_no){
		$SHOW = clone_( $this->CI->show_entity->init('ref_no', $show_ref_no));
		$BUYER = clone_( $this->CI->user_entity->init('id',$SHOW->getUserBidWon()));
		$SELLER = clone_( $this->CI->user_entity->init('id',$SHOW->getUserCreatedId()));
		$BID = clone_( $this->CI->bid_entity->is_set($account_code= $BUYER->getAccCode(), $show_ref_no=$SHOW->getRefNo()) );
		
		$slug = "notify_admin_send_email_to_bank_release_fund";
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array(		"{###BUYER_ID###}" ,
								"{###SHOW_LINK###}" 
						);
		$ref_link = "<a href='".site_url('admin/dataman/show/bid/?show_id='.$SHOW->getId())."'>".$SHOW->getRefNo()."</a>";
		$rplArr = array( 	
							$BUYER->getAccCode(),
							$ref_link 
						);
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($this->emailAdmin);
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();
	}
	
	
	//23. Seller or Buyer file dispute, funds nett of fees will be released to Buyer, all parties to be notified (full fee held till show close, then buyer will be refunded if show not bought by him ( to prevent deals outside the system)
	// slug: seller-buyer-file-dispute-fund-net-fee-release
	// TPL_21
	function _sendEmailToAll_notifySellerOrBuyerFileDispute($show_ref_no){
		$SHOW = clone_( $this->CI->show_entity->init('ref_no', $show_ref_no));
		$BUYER = clone_( $this->CI->user_entity->init('id',$SHOW->getUserBidWon()));
		$SELLER = clone_( $this->CI->user_entity->init('id',$SHOW->getUserCreatedId()));
		
		$slug = "seller-buyer-file-dispute-fund-net-fee-release";
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array(		"{###BUYER_NAME###}" ,
								"{###LINK###}" 
						);
		$ref_link = "<a href='".site_url('seller/show_details/'.$SHOW->getRefNo())."'>".$SHOW->getRefNo()."</a>";
		$rplArr = array( 	
							$BUYER->getFirstName().' '.$BUYER->getLastName(),
							$ref_link 
						);
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($SELLER->getEmail());
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();
		
		$this->setToEmail($BUYER->getEmail());
		$this->sendEmail();
		
		$this->setToEmail($this->emailAdmin);
		$this->sendEmail();
	}
	
	//Reminder to Admin to send email to Bank to release funds net to fees and commission to Buyer
	// slug: remind_admin_send_email_to_bank_release_fund__
	// TPL_21_a
	function _sendEmailToAdmin_remindAdminSendEmailToBankReleaseFund($show_ref_no){
		$SHOW = clone_( $this->CI->show_entity->init('ref_no', $show_ref_no));
		$BUYER = clone_( $this->CI->user_entity->init('id',$SHOW->getUserBidWon()));
		$SELLER = clone_( $this->CI->user_entity->init('id',$SHOW->getUserCreatedId()));
		
		$slug = "remind_admin_send_email_to_bank_release_fund__";
		$template = $this->CI->module_helper->getTemplateMail( $slug );
		$orgArr = array(		"{###BUYER_ID###}" ,
								"{###LINK###}" 
						);
		$ref_link = "<a href='".site_url('admin/dataman/show/bid/?show_id='.$SHOW->getId())."'>".$SHOW->getRefNo()."</a>";
		$rplArr = array( 	
							$BUYER->getAccCode(),
							$ref_link 
						);
		$body = str_replace( $orgArr , $rplArr , $template['body'] );
		$subject = $template['subject'];
		
		$this->setToEmail($this->emailAdmin);
		$this->setSubject($subject);
		$this->setBody($body);
		$this->sendEmail();
	}
	
	//end class
}	

